#include "./ui_mainwindow.h"
#include "mainwindow.h"
#include "stdafx.h"

void MainWindow::on_stop_clicked () { //暂停
    stop_cnt+=1;
    double sd = ui->speed->text ().toDouble ();
    if (!isstop) {
        ui->speed->setDisabled (false);
        ui->Auto->setDisabled (false);
        QPixmap ic;
        ic.load ("://icons/124.png");
        ui->stop->setIcon (ic);
        int tt = tim.elapsed ();
        timer.stop ();
        for (int i = 0; i < tmr_cnt; i++) { //计算剩余时间
            tmr[i].nxt -= tt;
            if (tmr[i].id != 1001 || sd > 1) {
                tmr[i].time = int ((tmr[i].time + tmr[i].extra) * sd + 0.1);
                tmr[i].nxt *= sd;
            }
            if (tmr[i].nxt < 0)
                tmr[i].nxt = 0;
        }
        isstop = true;
    }
    else {
        ui->speed->setDisabled (true);
        ui->Auto->setDisabled (true);
        QPixmap ic;
        ic.load ("://icons/117.png");
        ui->stop->setIcon (ic);
        for (int i = 0; i < tmr_cnt; i++) { //计算剩余时间
            if (tmr[i].id != 1001 || sd > 1) {
                tmr[i].nxt /= sd;
                double tj = tmr[i].time / sd;
                tmr[i].time = floor (tj);
                tmr[i].extra = tj - tmr[i].time;
            }
            tmr[i].nxt += tim.elapsed ();
        }
        isstop = false;
        ResetTimer ();
    }
    ui->prog->setFocus ();
}
void MainWindow::on_lineEdit_textEdited (const QString &arg1) {
    r_gq = m_gq = arg1.toInt ();
    if (m_gq == MAXGQS + 4)
        ui->Doub->setChecked (1);
    if (m_gq == MAXGQS + 1 || m_gq == MAXGQS + 2 || m_gq == MAXGQS + 4)
        ui->Short->setChecked (0);
    if (m_gq == MAXGQS + 6)
        ui->Short->setText (tr ("随机"));
    else if (m_gq == MAXGQS + 4)
        ui->Short->setText (tr ("预设"));
    else
        ui->Short->setText (tr ("短时"));
}
void MainWindow::on_save_clicked () {
    bool bk = false;
    if (!isstop)
        on_stop_clicked (), bk = true;
    auto fileDialog = std::make_unique<QFileDialog> (this);
    fileDialog->setAcceptMode (QFileDialog::AcceptSave);
    fileDialog->setWindowTitle (tr ("选择文件"));
    fileDialog->setNameFilter (tr ("大战僵尸存档(*)"));
    fileDialog->setFileMode (QFileDialog::AnyFile);
    fileDialog->setViewMode (QFileDialog::Detail);
    if (fileDialog->exec ()) {
        m_ai = ui->Auto->isChecked ();
        auto st = fileDialog->selectedFiles ();
        QString na;for (auto a : st)na = a;
        QFile file (na);
        file.open (QIODevice::WriteOnly);
        QDataStream ar (&file);
        Save (ar);
        file.close ();
    }
    if (bk)
        on_stop_clicked ();
    ui->prog->setFocus ();
}
void MainWindow::on_open_clicked () {
    auto fileDialog = std::make_unique<QFileDialog> (this);
    fileDialog->setAcceptMode (QFileDialog::AcceptOpen);
    fileDialog->setWindowTitle (tr ("选择文件"));
    fileDialog->setNameFilter (tr ("大战僵尸存档(*)"));
    fileDialog->setFileMode (QFileDialog::ExistingFile);
    fileDialog->setViewMode (QFileDialog::Detail);
    if (fileDialog->exec ()) {
        m_game.KillAll ();
        GameOver ();
        m_game.started = false;
        auto st = fileDialog->selectedFiles ();
        QString na;for (auto a : st)na = a;
        QFile file (na);
        file.open (QIODevice::ReadOnly);
        QDataStream ar (&file);
        Load (ar);
        file.close ();
        DOU = (SI == 55);
        for (int i = 0; i < MN; i++)
            m_game.row_zmb[i] = 0;
        for (int i = 0; i < m_game.zmb_cnt; i++) {
            m_game.row_zmb[m_game.zombies[i].y] += 1;
            m_game.zombies[i].num = i;
        }
        for (int i = 0; i < m_game.plt_cnt; i++)
            m_game.plants[i].num = i;
        m_game.CalZw ();
        m_game.SZZ = false;
        m_game.m_wnd = this;
        m_game.over = false;
        double sd = ui->speed->text ().toDouble ();
        for (int i = 0; i < tmr_cnt; i++) {
            if (tmr[i].id != 1001 || sd > 1) {
                tmr[i].nxt /= sd;
                double tj = tmr[i].time / sd;
                tmr[i].time = floor (tj);
                tmr[i].extra = tj - tmr[i].time;
            }
            tmr[i].nxt += tim.elapsed ();
        }
        int ms = -1;
        ResetTimer ();
        for (int n = 0; n < ND - 1; n++)
            ms += int (m_jg[n] / m_time[n]);
        if (ms == -1)
            ms = 1;
        if (is11)
            ui->prog->setRange (0, MN * (SI <= 55 ? 3000 : 1000));
        else
            ui->prog->setRange (0, ms);
        ui->prog->setValue (jd);
        ui->lineEdit->setText (QString::asprintf ("%d", r_gq));
        on_stop_clicked ();
        ui->Auto->setChecked (m_ai);
        ui->Doub->setChecked (DOU);
        ui->buy->setVisible (1);
        ui->speed->setEnabled (0);
        ui->easy->setEnabled (0);
        ui->normal->setEnabled (0);
        ui->hard->setEnabled (0);
        ui->Doub->setEnabled (0);
        ui->xin->setEnabled (0);
        ui->tui->setEnabled (0);
        ui->water->setEnabled (0);
        ui->creative->setEnabled (0);
        ui->Short->setEnabled(0);
        m_game.started = true;
        ShowButton ();
        Initicon ();
    }
}
void MainWindow::on_Auto_stateChanged (int arg1) {
    if (!m_game.started)
        return;
    if (arg1)
        tmr[tmr_cnt++] = MyTimer (1008, 400, 400, 0);
    else
        KillTimer (1008);
    m_ai = arg1;
}
void MainWindow::on_buy_clicked () {
    bool bk = false;
    if (!isstop)
        on_stop_clicked (), bk = true;
    int hf=450;if(sun_dou)hf*=2;
    if (QMessageBox::question (this, tr ("提示"), QString::asprintf("花费%d阳光购买一颗能量豆",hf)) == QMessageBox::Yes) {
        if (beans == 5) {
            QMessageBox::warning (this, tr ("提示"), tr ("能量豆数量已达到上限！"));
            ui->prog->setFocus ();
            return;
        }
        if (m_game.m_yg < hf) {
            QMessageBox::warning (this, tr ("提示"), tr ("阳光不足！"));
            ui->prog->setFocus ();
            return;
        }
        m_game.m_yg -= hf;
        beans += 1;
        gl->update ();
        gx->update ();
    }
    if (bk)
        on_stop_clicked ();
    ui->prog->setFocus ();
}
void MainWindow::on_quick_clicked () {
    bool bk = false;
    if (!isstop)
        on_stop_clicked (), bk = true;
    if (QMessageBox::question (this, tr ("提示"), tr ("此操作可以加速回复30秒，要求至少6000阳光，操作后阳光将除以2")) == QMessageBox::Yes) {
        if (m_game.m_yg < 6000) {
            QMessageBox::warning (this, tr ("提示"), tr ("阳光不足！"));
            ui->prog->setFocus ();
            return;
        }
        m_game.m_yg /= 2;
        if (cd_spd[0] > 100) {
            for (int i = 0; i < XUAN; i++) {
                int t = plants[m_xuan[i]].type;
                if (t != 3 && t != 5 && t != 7 && t != 16 && t != 30 && t != 31)
                    cd_spd[m_xuan[i]] /= 10000;
            }
            KillTimer (1010);
        }
        if (!isstop)
            SetTimer (1010, 30000, NULL);
        else
            tmr[tmr_cnt++] = MyTimer (1010, 30000, 30000, 0);
        for (int i = 0; i < XUAN; i++) {
            int t = plants[m_xuan[i]].type;
            if (t != 3 && t != 5 && t != 7 && t != 16 && t != 30 && t != 31)
                cd_spd[m_xuan[i]] *= 10000;
        }
    }
    if (bk)
        on_stop_clicked ();
    ui->prog->setFocus ();
}

void MainWindow::on_huisu_clicked () { //回溯
    ui->prog->setFocus();
    if(b_ycl)//进攻
    {
        ui->huisu->setEnabled(0);
        for(int i=0;i<MAXSHU;i++)
        {
            if(i!=38)
                cd_spd[i]-=800,cd[i]=0;
        }
        if(r_gq==MAXGQS+13)
        {
            m_game.freeze_all=false;
            return;
        }
        b_fast=ui->Short->isChecked();
        SetTimer (1002, m_time[0], NULL);
        SetTimer (1004, m_jg[0], NULL);
        SetTimer (1003, (m_b48 ? 10000 : 6000), NULL);
        if(b_fast)//瞬间模式
        {
            while(!m_game.over)
            {
                ResetTimer();
                OnTimer();
            }
        }
        return;
    }
    int t = ui->dfnz->text ().toInt ();
    if (t == 0)return;
    bool bb = false;
    if (!m_game.started) {//直接进入
        h_sd = -m_gq;
        b_hui = true;
        b_rd = false;
        bb = true;
        SetTimer (1011, 100, NULL);
        ResetTimer ();
    }
    w_tm = t;
    HuiFang (true);
    if (bb)
        Initicon ();
}

void MainWindow::on_creative_stateChanged(int arg1)
{
    if(arg1)
        QMessageBox::warning(this,tr("警告"),tr("开启此选项可能会影响游戏体验。"));
}

void MainWindow::on_btc_clicked () //开始
{
    w_tm = 0;h_sd = 1;
    b_rd = b_hui = arc=wait=false;
    if (m_game.started) {
        bool bk = false;
        if (!isstop)
            on_stop_clicked (), bk = true;
        if (QMessageBox::question (this, tr ("提示"), tr ("此操作将结束正在进行的游戏")) != QMessageBox::Yes) {
            if (bk)
                on_stop_clicked ();
            ui->prog->setFocus ();
            return;
        }
        isstop = false;
        QPixmap ic;
        ic.load ("://icons/117.png");
        ui->stop->setIcon (ic);
    }
    m_gq = r_gq;
    DOU = ui->Doub->isChecked ();
    m_ai = ui->Auto->isChecked ();
    if (m_gq < 0) //回放
    {
        w_tm = 1;
        h_sd = -m_gq;
        b_hui = true;
        SetTimer (1011, 100, NULL);
        b_rd = true;
        ResetTimer ();
        return;
    }
    if ((m_gq < 1 || m_gq > ZGQS) && m_gq != 2048)
        return;
    GameOver ();
    DisableButton();
    ui->Auto->setEnabled (0);
    ui->huisu->setEnabled(1);
    ui->hui->setEnabled(0);
    ui->luj->setEnabled(0);
    try {
        StartGame (MakeGq (m_gq));
    }
    catch (...) {
        GameOver ();
        return;
    }
    ui->prog->setFocus ();
    ShowButton ();
    update ();
}

void MainWindow::DisableButton()
{
    ui->speed->setEnabled (0);
    ui->easy->setEnabled (0);
    ui->normal->setEnabled (0);
    ui->hard->setEnabled (0);
    ui->Doub->setEnabled (0);
    ui->xin->setEnabled (0);
    ui->tui->setEnabled (0);
    ui->water->setEnabled (0);
    ui->creative->setEnabled (0);
    ui->Short->setEnabled(0);
}

void MainWindow::EnableButton()
{
    ui->speed->setEnabled (1);
    ui->easy->setEnabled (1);
    ui->normal->setEnabled (1);
    ui->hard->setEnabled (1);
    ui->xin->setEnabled (1);
    ui->tui->setEnabled (1);
    ui->water->setEnabled (1);
    ui->Doub->setEnabled (1);
    ui->Short->setEnabled (1);
    ui->Auto->setEnabled (1);
    ui->creative->setEnabled (1);
    ui->hui->setEnabled(1);
    ui->luj->setEnabled(1);
    ui->dfn->setVisible(1);
    ui->dfnz->setVisible(1);
    ui->huisu->setVisible(1);
    ui->hui->setVisible(1);
    ui->luj->setVisible(1);
}

void MainWindow::ShowButton () {//显示/隐藏按钮
    if (r_gq == 61 || m_gq == 63 || b_zhu || b_guan) {
        ui->buy->setVisible (0);
        ui->quick->setVisible (0);
    }
    else {
        ui->buy->setVisible (1);
        ui->quick->setVisible (1);
    }
    if(!ui->hui->isChecked())
    {
        ui->dfn->setVisible(0);
        ui->dfnz->setVisible(0);
        ui->hui->setVisible(0);
        ui->luj->setVisible(0);
        if(!b_ycl)
            ui->huisu->setVisible(0);
    }
}

void MainWindow::mouseReleaseEvent (QMouseEvent *event) {
    if (!m_game.started)
        return;
    if (isstop)
        return;
    if (event->button () == Qt::LeftButton) {
        bool t = false;
        QPoint pt = SPoint (event->pos ().x (), event->pos ().y ());
        if (pt.x () >= 150 && pt.y () >= 60) {
            int x = int ((pt.x () - 150) / SI) * SI;
            int y = int ((pt.y () - 60) / SI);
            if(select==-1&&wait)
            {
                int tx=x/SI;
                if(tx>0&&tx<MM&&y>=0&&y<MN)
                    keep[tx][y]^=1;
            }
            t = (select != -1);
            if (select == -2) {
                if (imjs) {//我是僵尸（铲除）
                    int zx = 1e9, wz = -1;
                    for (int i = 0; i < m_game.zmb_cnt; i++) //寻找最近的
                    {
                        if (m_game.zombies[i].type >= 100)
                            continue;
                        int t = abs (pt.x () - 150 - SI / 2 - m_game.zombies[i].x);
                        if (t < zx)
                            zx = t, wz = i;
                    }
                    if (zx <= SI / 2) //铲除僵尸
                    {
                        m_game.zombies[wz].life -= 80;
                        if (m_game.zombies[wz].life <= 0)
                            m_game.DestroyJs (wz);
                        else
                            m_game.zombies[wz].id = GetJsIcon (m_game.zombies[wz], m_game);
                    }
                }
                else if (!chui) {//挖去植物
                    m_game.m_ng[x / SI][y] = m_game.m_dc[x / SI][y] = 0;
                    m_game.DestroyZw (x, y);
                    select = -1;
                }
            }
            else if (select == -4) //大招
            {
                SolveDz (pt);
                select = -1;
            }
            else if (imjs)
                AddJs (pt);
            else
                AddPlant (pt);
            if (!t&&sele_x != -1) //WSAD
            {
                int x = ((pt.x () - 150) / SI) * SI;
                int y = ((pt.y () - 60) / SI);
                SolveWSAD(x,y);
            }
        }
        if (m_b48 && !t) //2048手势
        {
            int x = event->pos ().x (), y = event->pos ().y ();
            x -= l_x; y -= l_y;
            if (x * x + y * y >= 5000) {
                double jj = atan2 (y, x), p4 = acos (-1.0) / 4.0;
                if (jj > -p4 - eps && jj < p4 + eps)
                    right2048 ();
                else if (jj > p4 - eps && jj < 3 * p4 + eps)
                    down2048 ();
                else if (jj > -3 * p4 - eps && jj < -p4 + eps)
                    up2048 ();
                else
                    left2048 ();
            }
        }
    }
    else if (event->button () == Qt::RightButton) {
        QPoint pt = SPoint (event->pos ().x (), event->pos ().y ());
        SolveDz (pt);
    }
}
void MainWindow::mouseDoubleClickEvent (QMouseEvent *event) {
    if (!m_game.started)
        return;
    if (isstop)
        return;
    if (event->button () == Qt::MiddleButton) //挖
    {
        QPoint pt = SPoint (event->pos ().x (), event->pos ().y ());
        int x = ((pt.x () - 150) / SI) * SI;
        int y = ((pt.y () - 60) / SI);
        if (x >= 0 && x <= (MM - 1) * SI && y >= 0 && y < MN && XUAN) {
            m_game.m_ng[x / SI][y] = 0;
            m_game.DestroyZw (x, y);
        }
    }
}
void MainWindow::mousePressEvent (QMouseEvent *event) //同上
{
    if (!m_game.started)
        return;
    if (isstop)
        return;
    if (event->button () == Qt::LeftButton) {
        bool t = (select == -1);
        QPoint pt = SPoint (event->pos ().x (), event->pos ().y ());
        if (pt.x () >= 150 && pt.y () >= 60) {
            if (select != -1) {
                if (select == -2) {
                    int x = int ((pt.x () - 150) / SI) * SI;
                    int y = int ((pt.y () - 60) / SI);
                    if (chui) {
                        int zx = 1e9, wz = -1;
                        for (int i = 0; i < m_game.zmb_cnt; i++) {
                            if (m_game.zombies[i].type >= 100 || m_game.zombies[i].y != y)
                                continue;
                            int t = abs (pt.x () - 150 - SI / 2 - m_game.zombies[i].x);
                            if (t < zx)
                                zx = t, wz = i;
                        }
                        if (zx <= SI / 2) {
                            zx = abs (m_game.zombies[wz].x - 500);
                            m_game.zombies[wz].life -= 80;
                            if (m_game.zombies[wz].life <= 0)
                                m_game.DestroyJs (wz);
                            else
                                m_game.zombies[wz].id = GetJsIcon (m_game.zombies[wz], m_game);
                            if (zx <= SI / 3)
                                y_sum += SI / 3 - zx;
                        }
                        if (imjs)
                            select = -1;
                    }
                    else {
                        m_game.m_ng[x / SI][y] = m_game.m_dc[x / SI][y] = 0;
                        m_game.DestroyZw (x, y);
                        select = -1;
                    }
                }
                else if (select == -4) {
                    SolveDz (pt);
                    select = -1;
                }
                else if (imjs) {
                    if (!AddJs (pt))
                        t = true;
                }
                else if (!AddPlant (pt))
                    t = true;
            }
            else if (sele_x != -1) {
                int x = ((pt.x () - 150) / SI) * SI;
                int y = ((pt.y () - 60) / SI);
                SolveWSAD(x,y);
            }
        }
        else
            t = true;
        if (t) {
            int y = int (pt.y () / 50.0);
            if (pt.y () > 550 && pt.y () <= 610 && pt.x () >= 50 && pt.x () <= 100 && beans)
                select = -4;
            else if (pt.y () > 550 && pt.y () <= 610 && pt.x () < 50)
                select = -2;
            else if (imjs) {
                if (pt.x () <= 100 && y < MXUAN)
                    select = x_js[y];
            }
            else if (pt.x () <= 100 && y < XUAN && y < SHU - (is11) && m_game.m_yg >= plants[m_xuan[y]].cost)
                select = m_xuan[y];
            int x = int ((pt.x () - 150) / SI);
            y = int ((pt.y () - 60) / SI);
            if (pt.x () >= 150 && (m_gq == MAXGQS + 3 ||m_gq == MAXGQS + 14)&& y < MN && x >= 0 && x < MM && (m_game.GetZwShu (x * SI, y) != -1 || m_game.m_dc[x][y])) {
                sele_x = x * SI;
                sele_y = y;
            }
        }
        l_x = event->pos ().x ();
        l_y = event->pos ().y ();
    }
    else if (event->button () == Qt::MiddleButton)
        select = -1;
}
void MainWindow::keyPressEvent (QKeyEvent *event) {
    if (!m_game.started)
        return;
    int z = event->key ();
    m_zf[++zf_len]=z;
    if(zf_len>=4&&m_zf[zf_len-3]==Qt::Key_K&&m_zf[zf_len-2]==Qt::Key_I&&m_zf[zf_len-1]==Qt::Key_L&&m_zf[zf_len]==Qt::Key_L)//kill指令
    {
        m_game.zmb_cnt=0;
        for(int i=0;i<MN;i++)
            m_game.row_zmb[i]=0;
    }
    if(zf_len>=3&&m_zf[zf_len-2]==Qt::Key_S&&m_zf[zf_len-1]==Qt::Key_U&&m_zf[zf_len]==Qt::Key_N)//sun指令
        SwitchSun();
    if(z==Qt::Key_Escape)select=-1;
    if(z==Qt::Key_C&&(m_gq==MAXGQS||m_game.endless||m_gq==MAXGQS+14||ui->creative->isChecked())&& !m_ai)ChangeZw();
    if(z==Qt::Key_X)ShowLife();
    if(z==Qt::Key_R&&ui->creative->isChecked())
    {
        while(m_game.plt_cnt)
            m_game.DestroyZw(0);
        for(int i=0;i<MN;i++)
        {
            for(int j=0;j<MM;j++)
                m_game.m_dc[j][i]=0,m_game.m_ng[j][i]=500;
        }
        int ban[13]={3,5,19,20,21,24,28,29,30,31,38,42,43};
        for(int i=0;i<MN;i++)
        {
            for(int j=0;j<MM;j++)
            {
                int w;
                while(1)
                {
                    w=rand()%MAXSHU;
                    bool zd=0;
                    for(int k=0;k<13;k++)
                        if(ban[k]==w)
                        {zd=1;break;}
                    if(!zd)break;
                }
                Plant zw=plants[w];
                if(w==37)zw.tag=4;
                zw.mush=false;
                zw.x=j*SI;zw.y=i;
                m_game.NewZw(zw);
            }
        }
    }
    bool b = false;
    if (z == ' ') //暂停
    {
        on_stop_clicked ();
        return;
    }
    if (isstop)
        return;
    if (z >= Qt::Key_1 && z <= Qt::Key_9)//快捷键
        select = z - Qt::Key_1, b = 1,sele_x=-1;
    else if (z == Qt::Key_0)
        select = 9, b = 1,sele_x=-1;
    else if (z == Qt::Key_Minus)
        select = 10, b = 1,sele_x=-1;
    else if (z == '`') //铲子
        select = -2,sele_x=-1;
    else if (sele_x != -1) //可以WSAD
    {
        int tx = sele_x, ty = sele_y;
        if (z == Qt::Key_W || z == Qt::Key_Up)
            ty -= 1;
        else if (z == Qt::Key_S || z == Qt::Key_Down)
            ty += 1;
        else if (z == Qt::Key_A || z == Qt::Key_Left)
            tx -= SI;
        else if (z == Qt::Key_D || z == Qt::Key_Right)
            tx += SI;
        SolveWSAD(tx,ty);
    }
    else if (m_b48) //2048
    {
        if (z == Qt::Key_W || z == Qt::Key_Up)
            up2048 ();
        else if (z == Qt::Key_S || z == Qt::Key_Down)
            down2048 ();
        else if (z == Qt::Key_A || z == Qt::Key_Left)
            left2048 ();
        else if (z == Qt::Key_D || z == Qt::Key_Right)
            right2048 ();
    }
    if (b) { //处理选择的项目
        if (imjs)
            select = x_js[select];
        else if (select >= XUAN || select >= SHU - (is11))
            select = -1;
        else {
            if (m_game.m_yg >= plants[m_xuan[select]].cost)
                select = m_xuan[select];
            else
                select = -1;
        }
    }
}

void MainWindow::ViewStatus () {//查看状态
    if (!m_game.started)
        QMessageBox::information (this, tr (""), tr ("游戏还没有开始"));
    else
        QMessageBox::information (this, tr (""), QString::asprintf ("总共出现了%d只僵尸，还剩下%d只，进度%.2lf%%\r\n预计剩余%.2lf分钟", jd, zom_cnt - jd, double (jd) / zom_cnt * 100, (m_ztm / 60000.0 - TM * 25 / 60000.0) / ui->speed->text ().toDouble ()));
}
void MainWindow::Quit () {
    exit (0);
}


void MainWindow::jiasu () {//加速
    bool bk = false;
    if (!isstop)
        on_stop_clicked (), bk = true;
    double sd = ui->speed->text ().toDouble ();
    sd += 0.25;
    if (sd > 15)
        sd = 15;
    ui->speed->setValue (sd);
    if (bk)
        on_stop_clicked ();
}
void MainWindow::jiansu () {//减速
    bool bk = false;
    if (!isstop)
        on_stop_clicked (), bk = true;
    double sd = ui->speed->text ().toDouble ();
    sd -= 0.25;
    if (sd < 0.25)
        sd = 0.25;
    ui->speed->setValue (sd);
    if (bk)
        on_stop_clicked ();
}
void MainWindow::Retina()
{
    b_ret=3-b_ret;
    Initicon();
}
void MainWindow::SwitchSun()
{
    sun_dou^=1;
    if(sun_dou)sun_doued=1;
    if(sun_dou)ui->a_sun->setText("单倍阳光");
    else ui->a_sun->setText("双倍阳光");
}
void MainWindow::ShowLife()
{
    show_life^=1;
    if(show_life)ui->a_xue->setText("隐藏血量");
    else ui->a_xue->setText("显示血量");
}
